﻿using Syspetro.Core.AppDeal;
using Syspetro.Core.CommandBus;
using Syspetro.Core.SysInterface;

namespace Syspetro.Core.Encrypt
{
    /// <summary>
    /// 密码加盐
    /// </summary>
    public class PswdMd5Command : Command
    {
        public string Pswd { get; set; }
        public string Account { get; set; }
    }

    public interface IPswdMd5CommandHandler : ICommandHandler<PswdMd5Command>, ITransientService
    {

    }
    public class PswdMd5CommandHandler : CommandHandler<PswdMd5Command>, IPswdMd5CommandHandler
    {
        private const string slat = "bj";
        public override SpActionResult<string> Execute(PswdMd5Command command)
        {
            if (string.IsNullOrEmpty(command.Pswd))
                return new SpActionResult<string> { Success = false, Msg = "密码不能为空" };
            else
            {
                string pswd = MD5Helper.MD5Encrypt64(command.Pswd + command.Account + slat);
                return new SpActionResult<string>(pswd);
            }
        }
    }
}
